<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
	<meta charset="utf-8" />
	<title></title>
	<meta name="description" content="overview & stats" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
	<link rel="stylesheet" href="static/css/font-awesome.min.css" />
	<link rel="stylesheet" href="static/css/ace.min.css" />
	<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
	<link rel="stylesheet" href="static/css/ace-skins.min.css" />
	<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
	
	<script type="text/javascript">
		$(top.hangge());
		
		//新增
		function add(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增字典目录";
			 diag.URL = '<%=basePath%>/dictionary/toAddDictionaryCatalog.do';
			 diag.Width = 223;
			 diag.Height = 175;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					var num = '${page.currentPage}';
				 	if(num == '0'){
				 		top.jzts();
				 		location.href = location.href;
				 	}else{
				 		nextPage(${page.currentPage});
				 	}
				}
				 diag.close();
			 };
			 diag.show();
		}
		
		//修改
		function edit(cataid){
			 top.jzts();
		   	 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="编辑字典目录";
			 diag.URL = '<%=basePath%>/dictionary/toEditDictionaryCatalog/'+cataid+".do";
			 diag.Width = 223;
			 diag.Height = 175;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					 nextPage(${page.currentPage});
				}
				 diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function del(cataid,catacode){
			var flag = false;
			if(confirm("确定要删除该数据吗?")){
				flag = true;
			}
			
			if(flag){
				top.jzts();
				<%-- var url = "<%=basePath%>/dictionary/del.do?cataid="+cataid+"&guid="+new Date().getTime();
				$.get(url,function(data){
					if(data=="success"){
						top.jzts();
						nextPage(${page.currentPage});
					}else{
						alert("删除失败，请先删除此目录下的所有字典数据!"); 
						return false;
					}
				}); --%>
				
				$.ajax({
					type : "DELETE",
					url : "dictionary/deleteDictionaryCatalog/"+cataid+"/"+catacode+".json",
					//data:JSON.stringify(saveData),
					contentType:"application/json",  //发送至服务器的类型
					//dataType : "json",     //预期服务器返回类型
					success: function(data){
						//alert(data);
						//return false;
						if(data.string=="success"){
							top.jzts();
							nextPage(${page.currentPage});
						}else{
							alert("删除失败，请先删除此目录下的所有字典数据!"); 
							$(top.hangge());
							return false;
						}
					}
				})
			}
		}
	</script>
</head>
<body>
<div id="page-content" class="clearfix">
	<div class="row-fluid">
		<!-- 检索  -->
		<form action="<%=basePath%>/dictionary.do" method="GET" name="DictionaryCatalogForm" id="DictionaryCatalogForm">
		<table>
			<tr>
				<td><font color="#808080">检索：</font></td>
				<td><input type="text" name="cataname" value="${pageData.cataname }" placeholder="这里输入名称" style="width:130px;"/></td>
				<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="search();"><i id="nav-search-icon" class="icon-search"></i></button></td>
			</tr>
		</table>
		<!-- 检索  -->
		<table id="table_report" class="table table-striped table-bordered table-hover">
			<thead>
			<tr>
				<th class="center"  style="width: 50px;">序号</th>
				<th class='center'>目录名称</th>
				<th class='center'>编码</th>
				<th class='center'>操作</th>
			</tr>
			</thead>
			<c:choose>
				<c:when test="${not empty dictionaryCatalogList}">
					<c:forEach items="${dictionaryCatalogList}" var="var" varStatus="vs">
					<tr>
					<td class="center">${var.sort }</td>
					<td class='center'>
						<a href="<%=basePath%>/dictionary/listDictionary/${var.catacode }.do" title="查看字典定义">
						<i class="icon-arrow-right  icon-on-right"></i>&nbsp;${var.cataname }</a>
					</td>
					<td class='center'>${var.catacode }</td>
					<td style="width: 68px;">
						<a class='btn btn-mini btn-info' title="编辑" onclick="edit('${var.cataid }')" ><i class='icon-edit'></i></a>
						<a class='btn btn-mini btn-danger' title="删除"  onclick="del('${var.cataid }','${var.catacode }')"><i class='icon-trash'></i></a>
					</td>
					</tr>
					</c:forEach>
				</c:when>
				<c:otherwise>
					<tr>
						<td colspan="100" class="center">没有相关数据</td>
					</tr>
				</c:otherwise>
			</c:choose>
		</table>
		
		<div class="page-header position-relative">
			<table style="width:100%;">
				<tr>
					<td style="vertical-align:top;width:50px;"><a class="btn btn-small btn-success" onclick="add();">新增</a></td>
					<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
</div>
</body>
</html>